<template>
    <div class="system">
        <Breadcrumb>
            <BreadcrumbItem >账单管理</BreadcrumbItem>
        </Breadcrumb>
        <Divider />

        账单类型： <i-input size="large" placeholder="large size" style="width:360px"></i-input>
        <br>
        <div class="wenzi">账单照片：</div>
         <div class="demo">
    <div class="demo-upload-list" v-if="hasImage">
      <img :src="imageUrl" />
      <div class="demo-upload-list-cover">
        <Icon type="ios-eye-outline" @click.native="handleView(imageUrl)"></Icon>
        <Icon type="ios-trash-outline" @click.native="handleRemove()"></Icon>
      </div>
    </div>
    <Upload
      :action="actionUrl"
      :format="['jpg','jpeg','png']"
      :max-size="2048"
      :on-exceeded-size="handleMaxSize"
      :on-success="handleSuccess"
      :show-upload-list="false"
      style=" width:58px;">
       <Button icon="ios-cloud-upload-outline">上传图片</Button>
    </Upload>

    <div class="demo-upload-list" v-for="(item,index) in imageUrlList" :key="index">
        <img :src="item.url" />
        <div class="demo-upload-list-cover">
          <Icon type="ios-eye-outline" @click.native="handleView(item.url)"></Icon>
          <Icon type="ios-trash-outline" @click.native="handleRemoveList(index)"></Icon>
        </div>
    </div>

    <Upload
      :show-upload-list="false"
      :on-exceeded-size="handleMaxSize"
      :on-success="handleSuccessList"
      :format="['jpg','jpeg','png']"
      :max-size="2048"
      multiple
      type="drag"
      :action="actionUrl"
      style="display: inline-block;width:58px;">
      <div style="width: 110px;height:110px;line-height: 110px;">
        <Icon type="ios-camera" size="20"></Icon>
      </div>
    </Upload>
    <Modal title="图片预览" v-model="visible">
      <img :src="showImageUrl" v-if="visible" style="width: 100%" />
    </Modal>
  </div>
        <Button icon="md-add" type="primary" class="button">提交</Button>
    </div>
</template>
<script>
export default {
  name: 'slideshow',
  data () {
    return {
      self: this,
      actionUrl: '服务器请求地此，上传文件的接口',
      imageUrl: '',
      hasImage: false,
      showImageUrl: '',
      visible: false,
      imageUrlList: [
        {
          url: 'http://pic22.nipic.com/20120620/9644879_220135570113_2.jpg'
        }
      ]

    }
  },
  methods: {
    show (index) {
      this.$Modal.info({
        title: '用户信息',
        content: `姓名：${this.data6[index].name}<br>年龄：${this.data6[index].age}<br>地址：${this.data6[index].address}`
      })
    },
    remove (index) {
      this.data6.splice(index, 1)
    },
    handleMaxSize (file) {
      this.$Notice.warning({
        title: '图片大小限制',
        desc: '文件 ' + file.name + '太大,不能超过 2M.'
      })
    },
    upload () {
      this.loadingStatus = true
      setTimeout(() => {
        this.file = null
        this.loadingStatus = false
        this.$Message.success('Success')
      }, 1500)
    },
    handleView (imageUrl) {
      this.showImageUrl = imageUrl
      this.visible = true
    },
    handleRemove () {
      this.imageUrl = ''
      this.hasImage = false
    },
    handleRemoveList (index) {
      // 删除
      this.imageUrlList.splice(index, 1)
    },

    handleSuccessList (res, file) {
      let image = { url: res.data }
      console.log('image:' + image.url)
      this.imageUrlList.push(image)
      console.log(this.imageUrlList)
    },
    handleSuccess (res, file) {
      console.log(res)
      this.imageUrl = res.data
      this.hasImage = true
      console.log(file)
    }
  }
}
</script>
<style >
.demo{
  width: 500px;
  height: 220px;
  position: relative;
  left: 60px;
}
.wenzi{
  position: relative;
  top: 20px
}
.button{
  position: relative;
  left: 60px;
  top: -30px
}
.demo-upload-list {
   position: relative;
  margin-top: 5px;
  display: inline-block;width: 112px;height: 112px;text-align: center;line-height: 60px;
  border: 1px solid transparent;border-radius: 4px;overflow: hidden;background: #fff;
  position: relative;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);margin-right: 4px;
}
.demo-upload-list img {
  width: 100%;height: 100%;
}
.demo-upload-list-cover {
  display: none;position: absolute;top: 0;bottom: 0;
  left: 0;right: 0;background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list:hover .demo-upload-list-cover {
  display: block;
}
.demo-upload-list-cover i {
  color: #fff;font-size: 30px;cursor: pointer;margin: 0 3px;margin-top: 40px
}
.ivu-upload{
  width: 110px;
  position: relative;
  margin-left: 1px
}

</style>
